package demo;

public class HelloWorld { //Object
    int zIndex = 7;//成员变量
    static double BL = 0.01;//类变量（静态变量）
    static final double PI = 3.14;//类“常”量

    public static String testClass() {
        return "类方法";
    }//静态方法

    public String test() {
        return "成员方法";
    }

    public static void main(String[] args) {//void 没有返回值

        int z = 1;//变量
        System.out.println("z:" + z);
        z = 3;
        System.out.println("z:" + z);

        final int c = 1;//常量
        System.out.println("c:" + c);

        System.out.println("成员变量zIndex:" + new HelloWorld().zIndex);
        System.out.println("类变量:" + HelloWorld.BL);
        System.out.println("成员方法:" + new HelloWorld().test());
        System.out.println("类方法:" + HelloWorld.testClass());

        System.out.println("Hello World");

        AccessControl.testPublic();//访问权限控制
        AccessControl.testProtected();

        /**
         * 基础数据类型
         */
        String str1 = "Hello"; //字符串类型
        String str2 = "Java";
        String str = str1 + " " + str2;
        System.out.println(str);//Hello Java

        int n1 = 1; //整型
        int n2 = 2;
        int n = n1 + n2; //操作符+ - * / %
        System.out.println(n);//3

        final double PI = 3.14;//浮点类型（双精度）

        Boolean b = true; //布尔类型 true 或 false

        /**
         * 简化写法
         */
        int m = 0;
        m = m+1; //等价于m+=1;等价于m++;等价于++m (++m为优先+1，m++为滞后+1)
        int k = 0;
        k = k+3; //k+=3

        /**
         * 流程控制
         */
        int score = 65;
        if (score < 60) {//[0-60)
            System.out.println("不及格");
        } else if (score >= 60 && score < 70) {//[60-70)
            System.out.println("及格万岁");
        } else if (score >= 70 && score < 80) {//[70-80)
            System.out.println("表现平平");
        } else {//[80-100]
            System.out.println("优秀");
        }

        int age = 18;
        switch (age) {
            case 18:
                System.out.println("永远18岁");
                break;
            case 20:
                System.out.println("今年20岁");
                break;
            default:
                System.out.println("不是18岁，也不是20岁");
        }

        int sum = 0;
        for (int i = 0; i <= 3; i++) {
            System.out.println("遍历:" + i);
            sum += i;//sum = sum + i;
        }
        System.out.println("sum = " + sum);

        int v1 = 2;
        while (v1 < 10) {
            System.out.println("v1 = " + v1);
            v1 = v1 + 2;
        }

        int v2 = 2;//12
        do {
            System.out.println("v2 = " + v2);
            v2 = v2 + 2;
        } while (v2 < 10);

        int[] myArray = new int[5];
        myArray[0] = 0;
        myArray[1] = 1;
        myArray[2] = 2;
        myArray[3] = 3;
        myArray[4] = 4;
        System.out.println("数组长度=" + myArray.length);
        System.out.println("myArray[3]=" + myArray[3]);
        for (int index = 0; index < myArray.length; index++) {
            System.out.println("元素 " + index + " = " + myArray[index]);
        }

        System.out.println("-----------------------------------------");
        Animal animal = new Cat();
        animal.say();
        animal.move();

        System.out.println("-----------------------------------------");
        Cat cat = new Cat();
        cat.say();
        cat.move();
        cat.say("汪汪汪");

        System.out.println("-----------------------------------------");
        Animal ren = new Animal("人");
        System.out.println(ren.name);//给成员变量赋值
    }
}
